<template>
	<view class="page">
		<view class="p-list">
			<singleList ref="listRef" url="store.lists" :sendData="reqData" @reqEnd="searchEnd">
				<template v-slot:items="{ list }">
					<empty v-if="sRes && sRes==='empty'" marginTop="200rpx"></empty>
			
					<block v-for="(item, i) in list" :key="i">
						<doorItem :info="item" @del="del" />
					 </block>
				</template>
			</singleList>
		</view>
		<safe-area height="84rpx" bgColor="#f7f7f7">
			<template v-slot:btn>
				<view class="p-btn" @click="navTo('/pages/door/doorHandle')">
					新建门店
				</view>
			</template>
		</safe-area>
	</view>
</template>

<script lang="ts">
import {
	reactive,
	toRefs,
	defineComponent,
	ref,
	nextTick,
	// watchEffect,
} from 'vue';
import doorItem from './components/doorItem.vue';
import {  onShow,onPullDownRefresh,onReachBottom } from '@dcloudio/uni-app';
const doors = defineComponent({
	components: {
		doorItem
	},
	props: {},
	setup(props: any, ctx: any) {
		const data = reactive({
			reqData: {},
			sRes:'',
		});
		const listRef = ref();
		// onLoad(e => {
		// });
		onShow(() => {
			nextTick(() => {
				// data.reqData = {
				// 	status: data.tabs[data.tabCurIdx].status
				// };
				listRef.value.getList(true);
			});
		});
		onPullDownRefresh(()=>{
			listRef.value.getList(true);
			uni.stopPullDownRefresh();
		})
		onReachBottom(()=>{
			listRef.value.getList();
		})
		const searchEnd =({loadingType,pageOneRes})=>{
			if(loadingType === 'noMore' && pageOneRes && pageOneRes.length === 0){
				data.sRes='empty';
			}else{
				data.sRes=loadingType;
			}
		}
		const del =(info)=>{
			const {id,name} = info;
			uni.showModal({
				title:'提示',
				content:"确认删除"+name+"吗？",
				success: async (res) => {
					if(res.confirm){
						// await uni.$request('store.')
					}
				}
			})
		}
		return {
			...toRefs(data),
			listRef,
			searchEnd,
			del,
		};
	}
});
export default doors;
</script>

<style lang="scss">
	page {
		background-color: #f7f7f7;
	}
	.p-list {
		padding: 0 20rpx;
	}
	.p-btn{
		margin: 56rpx auto 0;
		width: 670rpx;
		height: 84rpx;
		background: #3E6FEF;
		border-radius: 84rpx;
		line-height: 84rpx;
		text-align: center;
		font-size: 32rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #FFFFFF;
		&.disabled{
			background-color: #eee;
		}
	}
</style>